package net.frenopatico.citadels.app;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;

import lombok.Getter;

import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
import com.vaadin.Application;
import com.vaadin.terminal.gwt.server.GAEApplicationServlet;

/**
 * Guice Servlet for Vaadin.
 *
 */
@Singleton
@Getter
public class GuiceApplicationServlet extends GAEApplicationServlet {
    private static final long serialVersionUID = -1606595499431626154L;
    private final Provider<Application> appProvider; // NOPMD

    /**
     * Constructs a Guice Servlet for Vaadin.
     *
     * @param newAppProvider Provider for Vaadin applications.
     */
    @Inject
    public GuiceApplicationServlet( final Provider<Application> newAppProvider ) {
        super();
        this.appProvider = newAppProvider;
    }

    @Override
    protected Class<Application> getApplicationClass() throws ClassNotFoundException {
        return Application.class;
    }

    @Override
    protected Application getNewApplication( final HttpServletRequest request ) throws ServletException {
        return appProvider.get();
    }

}
